<?php

function _d($var, $exit = false){
	echo '<pre>';
	print_r($var);
	echo '</pre>';
	if($exit) die();
}

function _getErrors(){
	$errs = array();
	if($_SESSION['msg']){
		foreach($_SESSION['msg'] as $err){
			$errs[] = $err;
		}
		$_SESSION['msg'] = array();
	}
	return $errs;
}

function _forward($location){
	header("location:$location");
	exit;
}

function _notFound(){
	header("HTTP/1.0 404 Nawawalang Record!!! Hahahaha");
	_d(_getErrors());
	exit;
}

function _conflict(){
	header("HTTP/1.0 409");
	_d(_getErrors());
	exit;
}

function _options($choices, $selected=""){
	$str = '<option value=""></option>';
	foreach($choices as $key=>$val){
		if($selected==$key){
			$str .='<option value="'.$key.'" selected="selected">'.$val.'</option>';
		}else{
			$str .='<option value="'.$key.'">'.$val.'</option>';
		}
	}

	return $str;
}